<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>PHP Functions</title>
</head>
<body>
<h1>PHP Functions</h1>

<div>
    <h3>Create a User Defined Function in PHP</h3>
    <?php
    function writeMsg()
    {
        echo("Hello world!");
    }

    writeMsg(); // call the function
    ?>
</div>
<div>
    <h3>PHP Function Arguments</h3>
    <?php
    function familyName($fname, $year = null)
    {
        if ($year == null) {
            echo("$fname ABC. <br>");
        } else {
            echo("$fname ABC. Born in $year <br>");
        }
    }

    familyName("Jani");
    familyName("Hege");
    familyName("Stale", 15);
    familyName("Kai Jim", 78);
    familyName("Borge", 90);
    ?>
</div>
<div>
    <h3>PHP Functions - Returning values</h3>
    <?php
    function sum($x, $y)
    {
        return ($x + $y);
    }

    echo "5 + 10 = " . sum(5, 10) . "<br>";
    echo "7 + 13 = " . sum(7, 13) . "<br>";
    echo "2 + 4 = " . sum(2, 4);
    ?>
</div>
</body>
</html>